package com.lfd.hashmap;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @项目名： spring-emq
 * @包名： com.lfd.hashmap
 * @文件名: ExecutorServiceExample
 * @创建者: liufudong@szyh-smart.com
 * @创建时间: 2024/10/13 16:03
 * @描述：
 */
public class ExecutorServiceExample {
    public static void main(String[] args) {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1,1,60, TimeUnit.SECONDS,
                new LinkedBlockingQueue<Runnable>());
      for (int i = 0; i < 10; i++) {
          final int finalI = i;
          threadPoolExecutor.submit(new Runnable() {
              @Override
              public void run() {
                  try {
                      Thread.sleep(1000);
                  } catch (InterruptedException e) {
                      throw new RuntimeException(e);
                  }
                  System.out.println("Task "+finalI+" is running");
              }
          });
      }
    }
}
